package com.daxt.common.result;

import com.daxt.common.exception.BaseException;
import org.apache.commons.lang3.StringUtils;

public class ResultUtil {
	public static   <T> Result<T> data(String code,String msg, T data) {
		Result<T> res = new Result<T>();
		res.setCode(String.valueOf(code));
		res.setMsg(msg);
		res.setData(data);
		return res;
	}

	public static <T> Result<T> result(int i) {
		if(i > 0)return success();
		return error();
	}


	public static <T> Result<T> success() {
		Result<T> res = new Result<>(ResultCode.RESULT_SUCCESS.getCode(),ResultCode.RESULT_SUCCESS.getMes());
		return res;
	}
	public static <T> Result<T> success(T data) {
		Result<T> res = new Result<>(ResultCode.RESULT_SUCCESS.getCode(),ResultCode.RESULT_SUCCESS.getMes(),data);
		return res;
	}
	public static <T> Result<T> success(String msg, T data) {
		Result<T> res = new Result<>(ResultCode.RESULT_SUCCESS.getCode(), StringUtils.isEmpty(msg)?ResultCode.RESULT_SUCCESS.getMes():msg,data);
		return res;
	}



	public static <T> Result<T> error() {
		Result<T> res = new Result<>(ResultCode.RESULT_ERROR.getCode(),ResultCode.RESULT_ERROR.getMes());
		return res;
	}
	public static <T> Result<T> error(String msg) {
		Result<T> res = new Result<>(ResultCode.RESULT_ERROR.getCode(),StringUtils.isEmpty(msg)?ResultCode.RESULT_ERROR.getMes():msg);
		return res;
	}
	public static <T> Result<T> error(String code ,String msg) {
		Result<T> res = new Result<>(StringUtils.isEmpty(msg)?ResultCode.RESULT_ERROR.getCode():code,StringUtils.isEmpty(msg)?ResultCode.RESULT_ERROR.getMes():msg);
		return res;
	}

}
